/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LapPhieuThuTien.java
 *
 * Created on Jul 10, 2010, 1:17:12 PM
 */

package GUI;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author May2
 */
public class LapPhieuThuTien extends javax.swing.JInternalFrame {

    public void hienThiDanhSachDaiLy(){
//        ArrayList<DaiLyPOJO> list = DaiLyBUS.selectDanhSachDaiLy();
//        //Đọc dữ liệu
//        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
//        for(int i=0; i<list.size(); i++){
//            //Đọc từng dòng
//            Vector ct = new Vector();
//            ct.add(list.get(i).getMaDaiLy());
//            ct.add(list.get(i).getTenDaiLy());
//            //Thêm một dòng vào model của JComboBox
//            dcbm.addElement(ct);
//        }
//        //Gán model cho JComboBox
//        this.jcbTenDaiLy.setModel(dcbm);
    }
    /** Creates new form LapPhieuThuTien */
    public LapPhieuThuTien() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbtThem = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jlbTenDaiLy = new javax.swing.JLabel();
        jcbTenDaiLy = new javax.swing.JComboBox();
        jlbDiaChi = new javax.swing.JLabel();
        jtfDiaChi = new javax.swing.JTextField();
        jlbDienThoai = new javax.swing.JLabel();
        jlbNgayThuTien = new javax.swing.JLabel();
        jlbSoTienThu = new javax.swing.JLabel();
        jtfDIenThoai = new javax.swing.JTextField();
        jtfSoTienThu = new javax.swing.JTextField();
        jtfNgayThuTien = new javax.swing.JTextField();
        jbtThoat = new javax.swing.JButton();

        setTitle("PHIEU THU TIEN");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jbtThem.setText("Thêm");
        jbtThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThemActionPerformed(evt);
            }
        });

        jPanel1.setBorder(new javax.swing.border.MatteBorder(null));

        jlbTenDaiLy.setText("Tên Cửa Hàng :");

        jcbTenDaiLy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbTenDaiLyActionPerformed(evt);
            }
        });

        jlbDiaChi.setText("Địa Chỉ :");

        jtfDiaChi.setEditable(false);

        jlbDienThoai.setText("Điện Thoại :");

        jlbNgayThuTien.setText("Ngày Thu Tiền :");

        jlbSoTienThu.setText("Số Tiền Thu :");

        jtfDIenThoai.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbTenDaiLy)
                    .addComponent(jlbDienThoai)
                    .addComponent(jlbDiaChi))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jtfDIenThoai)
                        .addComponent(jcbTenDaiLy, 0, 124, Short.MAX_VALUE)))
                .addGap(47, 47, 47)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbSoTienThu)
                    .addComponent(jlbNgayThuTien))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jtfSoTienThu, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                    .addComponent(jtfNgayThuTien))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbTenDaiLy)
                    .addComponent(jcbTenDaiLy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbNgayThuTien)
                    .addComponent(jtfNgayThuTien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbDienThoai)
                    .addComponent(jtfDIenThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbSoTienThu)
                    .addComponent(jtfSoTienThu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbDiaChi)
                    .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jbtThoat.setText("Thoát");
        jbtThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(jbtThem, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(42, 42, 42)
                        .addComponent(jbtThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtThem)
                    .addComponent(jbtThoat))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThemActionPerformed
        // TODO add your handling code here:
//        Vector vt = (Vector)this.jcbTenDaiLy.getSelectedItem();
//        int maDaiLy = (Integer)vt.get(0);
//
//        String ngay = this.jtfNgayThuTien.getText();
//        String array_ngay[] = ngay.split("-");
//        String ngayThuTien = "";
//        for(int i=3; i>0; i--){
//            ngayThuTien += array_ngay[i-1];
//            if(i!=1){
//                ngayThuTien += "-";
//            }
//        }
//
//        double soTienThu = Double.parseDouble(this.jtfSoTienThu.getText());
//
//        String n = ThongKeBUS.insertPhieuThuTien(maDaiLy, ngayThuTien, soTienThu);
//        if(n.equals("")){
//                JOptionPane.showMessageDialog(this, "Thêm thành công!!!");
//                DaiLyBUS.updateTienNoAll();
//        } else {
//                JOptionPane.showMessageDialog(this, n);
//        }
    }//GEN-LAST:event_jbtThemActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        this.hienThiDanhSachDaiLy();
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        String d = sdf.format(now);
        this.jtfNgayThuTien.setText(d);
    }//GEN-LAST:event_formInternalFrameOpened

    private void jcbTenDaiLyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTenDaiLyActionPerformed
        // TODO add your handling code here:
//        Vector vtTenDaiLy = (Vector)this.jcbTenDaiLy.getSelectedItem();
//        int maDaiLy = (Integer)vtTenDaiLy.get(0);
//        ArrayList<DaiLyPOJO> list = DaiLyBUS.searchDaiLy(maDaiLy);
//        for(int i=0; i<list.size(); i++){
//            this.jtfDIenThoai.setText(list.get(i).getDienThoai());
//            this.jtfDiaChi.setText(list.get(i).getDiaChi());
//            this.jtfEmail.setText(list.get(i).getEmail());
//        }
    }//GEN-LAST:event_jcbTenDaiLyActionPerformed

    private void jbtThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThoatActionPerformed
        // TODO add your handling code here:
        int reply = JOptionPane.showConfirmDialog(this, "Bạn có muốn thoát", "Thông báo", WIDTH);
        if(reply == JOptionPane.OK_OPTION){
            this.dispose();
        }
    }//GEN-LAST:event_jbtThoatActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jbtThem;
    private javax.swing.JButton jbtThoat;
    private javax.swing.JComboBox jcbTenDaiLy;
    private javax.swing.JLabel jlbDiaChi;
    private javax.swing.JLabel jlbDienThoai;
    private javax.swing.JLabel jlbNgayThuTien;
    private javax.swing.JLabel jlbSoTienThu;
    private javax.swing.JLabel jlbTenDaiLy;
    private javax.swing.JTextField jtfDIenThoai;
    private javax.swing.JTextField jtfDiaChi;
    private javax.swing.JTextField jtfNgayThuTien;
    private javax.swing.JTextField jtfSoTienThu;
    // End of variables declaration//GEN-END:variables

}
